package com.wyy.mapper;

import com.wyy.pojo.Users;
import com.wyy.pojo.model.UserToken;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @program: gytcb
 * @author: 吴磊
 * @create: 2021-06-02 11:01
 */
@Repository
public interface UsersMapper {

    /**
     * 根据用户名称模糊查询用户
     *
     * @param userToken
     * @return
     */
    List<UserToken> getUserByNameLike(UserToken userToken);

    /**
     * 获取模糊查询的用户数量
     *
     * @param userToken
     * @return
     */
    Integer getCountByNameLike(UserToken userToken);


    @Select("select * from users")
    List<Users> getAllUsers();

    /**
     * 通过用户名和密码获取用户
     *
     * @param userNickname
     * @param userPassword
     * @return
     */
    @Select("select * from users where (user_email = #{userNickname} or user_nickname = #{userNickname}) and user_password = #{userPassword}")
    Users getUserByUserNicknameAndPwd(@Param("userNickname") String userNickname,
                                      @Param("userPassword") String userPassword);

    /**
     * 通过用户昵称获取用户
     *
     * @param userNickname
     * @return
     */
    Users getUserByUserNickname(@Param("userNickname") String userNickname);

    /**
     * 通过邮箱获取用户
     *
     * @param userEmail
     * @return
     */
    @Select("select * from users where user_email = #{userEmail}")
    Users getUserByUserEmail(@Param("userEmail") String userEmail);

    /**
     * 插入用户
     *
     * @param users
     * @return
     */
    Integer insertUser(Users users);

    /**
     * 更新用户数据
     *
     * @param users
     * @return
     */
    Integer updateUser(Users users);

    /**
     * 通过用户Id获取用户
     *
     * @param userId
     * @return
     */
    @Select("select * from users where user_id = #{userId}")
    Users getUserById(@Param("userId") String userId);
}
